	// DateInput 日期输入
	var DateInput=function(selector){
		this.selector=selector;
		//this.init();
	}
	DateInput.prototype=new Control();
	DateInput.options={
		startDate:"1900-1-1",
		startDateNotFitTips:"不得早于预定的起始时间",
		
		endDate:"2099-12-31",
		endDateNotFitTips:"不得晚于预定的结束时间",
		
		startSelector:"",
		startSelectorNotFitTips:"不得早于选择的起始时间",
		
		endSelector:"",
		endSelectorNotFitTips:"不得晚于选择的结束时间"
	}
	DateInput.prototype.init=function(){
		this.element=$(this.selector).get(0);
		$(this.element).prop("type","text");
		
		$(this.element).addClass("ht-dateInput");
		
		var self=this;
		$(this.element).unbind("click");
		$(this.element).bind("click",function(event){
			self.clickHandle(event);
		})
		this.element.setAttribute("readonly","readonly")
		this.element.setAttribute("readOnly","readonly")
		this.options=this.getOptions();
	}
	DateInput.prototype.getOptions=function(){
		var optionsStr=this.element.getAttribute("data-options")
		var options=null;
		if(optionsStr==null){
			options={}
		}else{
			options=eval("({"+optionsStr+"})");
		}
		options=$.extend({},DateInput.options,options);
		return options;
	}
	DateInput.prototype.clickHandle=function(event){
		this.control=this.getControl();
		document.body.appendChild(this.control)
	}
	DateInput.prototype.getControl=function(){
		this.removeControl();
		var frame=$("<iframe frameborder=\"0\" scrolling=\"no\" class=\"ht-dateSelector\" src=\"/common/HTMLTurbo/0.3.0/module/control/dateInput/dateInput.html\"></iframe>").get(0);
		
		var top=$(this.element).offset().top+$(this.element).height()+5
		var left=$(this.element).offset().left
		
		frame.style.left=left+"px"
		frame.style.top=top+"px"
	
		var self=this;
		var value=this.getValue();
		
		var options={
			value:value,
			startDate:this.options.startDate,
			endDate:this.options.endDate,
			setDate:function(date){
				self.setDate(date)
			},
			setValue:function(value){
				self.setValue(value);
			},
			removeControl:function(){
				self.removeControl();
			}
		}
		
	
		$(frame).bind("load",function(){
			var calendar=frame.contentWindow.createCalendr(options);
			var buttonGroupElement=frame.contentWindow.createButtonGroup(options)
			
			/*
			//console.log("onload");
			//ie7 在页面中附加样式body无效
			frame.contentWindow.document.body.style.margin="0"
			frame.contentWindow.document.body.style.padding="0"
			frame.contentWindow.document.body.style.backgroundColor="#f8f8f8"
			
			frame.contentWindow.document.body.appendChild(calendar.getElement());
			frame.contentWindow.document.body.appendChild(buttonGroupElement);
			frame.focus();
			*/
		})
		var bodyClick=null;
		//$("body").unbind("click");
		$("body").bind("click",bodyClick=function(e){
			if($(e.target).closest(self.element).length==0 && $(e.target).closest(frame).length == 0){
				self.removeControl();
				$("body").unbind("click",bodyClick);
			}
	    });
		var bodyClick=function(){
			
		}
		/*$(frame).bind("mouseout",function(event){
			self.removeControl();
		})*/
		return frame;
	}
	DateInput.prototype.setDate=function(date){
		var value=Utils.getDateStr(date);
		if(this.checkDate(date)){
			this.setValue(value);
		}
	}
	DateInput.prototype.setStartSelector=function(startSelector){
		this.options.startSelector=startSelector
	}
	DateInput.prototype.setEndSelector=function(endSelector){
		this.options.endSelector=endSelector
	}
	
	DateInput.prototype.setStartDate=function(startDate){
		this.options.startDate=startDate
	}
	DateInput.prototype.setEndDate=function(endDate){
		this.options.endDate=endDate
	}
	DateInput.prototype.checkDate=function(date){
		if(this.options.endSelector!=""){
			var endValue=$(this.options.endSelector).val();
			var endDate=Utils.getDateByDateStr(endValue);
			if(endDate<date){
				alert(this.options.endSelectorNotFitTips);
				return false;
			}
		}
		
		if(this.options.startSelector!=""){
			var startValue=$(this.options.startSelector).val();
			var startDate=Utils.getDateByDateStr(startValue);
			if(startDate>date){
				alert(this.options.startSelectorNotFitTips);
				return false;
			}
		}
		
		var endValue=this.options.endDate;
		var endDate=Utils.getDateByDateStr(endValue);
		if(endDate<date){
			alert(this.options.endDateNotFitTips);
			return false;
		}
	
		var startValue=this.options.startDate;
		var startDate=Utils.getDateByDateStr(startValue);
		if(startDate>date){
			alert(this.options.startDateNotFitTips);
			return false;
		}
		return true;
	}
	DateInput.prototype.setValue=function(value){
		this.value=value;
		this.element.value=value
		this.element.focus();
		this.removeControl();
		$(this.element).change();
	}
	DateInput.prototype.getValue=function(){
		var value=this.element.value;
		return value;
	}
	DateInput.prototype.removeControl=function(){
		$(this.control).remove();
	}
	DateInput.prototype.getButtonGroup=function(options){
		var self=this;
		var container=document.createElement("div")
		container.className="buttonGroup"
		
		var todayElement=document.createElement("a");
		todayElement.innerHTML="今天"
		$(todayElement).bind("click",function(event){
			var dateTime=new Date();
			date=new Date(dateTime.getFullYear(),dateTime.getMonth(),dateTime.getDate())
			options.setDate(date);
		});
		
		
		var clearElement=document.createElement("a");
		clearElement.innerHTML="清除"
		$(clearElement).bind("click",function(event){
			options.setValue("");
			options.removeControl();
		});
		
		
		
		var closeElement=document.createElement("a");
		closeElement.innerHTML="关闭"
		$(closeElement).bind("click",function(event){
			options.removeControl();
		});
		
		container.appendChild(todayElement);
		container.appendChild(clearElement);
		container.appendChild(closeElement);
		return container
	}
	
	
	
	var Utils=function(){}
	Utils.getDate=function(year,month,day){
		var date=new Date(year,month,day);
		return date;
	}
	Utils.getDateByDateStr=function(value){
		//console.log(value);
		value=value.replace(/ .*/g,"");
		
		var dateArray=value.split("-");
		
		var year=dateArray[0];
		var month=dateArray[1];
		var day=dateArray[2];
		
		var date=new Date(year,(month-1),day);
		return date;
	}
	
	
	
	
	Utils.getDateStr=function(date){
		var year=date.getFullYear();
		var month=date.getMonth()+1;
		var day=date.getDate();
	
		if(month.toString().length==1){
			month="0"+month
		}
		var day=date.getDate()
		
		if(day.toString().length==1){
			day="0"+day.toString();
		}
		var dateStr=year+"-"+month+"-"+day;
		return dateStr;
	}
	Utils.getYearMonthDayLength=function(year,month){
		var leapYear = ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? true: false;
		var length;
		switch (parseInt(month)) {
			case 0:
			case 2:
			case 4:
			case 6:
			case 7:
			case 9:
			case 11:
				length = 31;
				break;
			case 3:
			case 5:
			case 8:
			case 10:
				length = 30;
				break;
			case 1:
				length = leapYear ? 29: 28;
		}
		return length;
	}
	HTMLTurbo.control.DateInput=DateInput;